<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <input type="text" v-model="textValue" />
      <button v-on:click="handleClick">添加</button>
      <ul>
        <li v-for="item in list">
          {{ item }} - <button v-on:click="removeItem(item)">删除</button>
        </li>
      </ul>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {
          list: ["zhangsan", "lisi"],
          textValue: "",
        },
        methods: {
          handleClick() {
            // console.log(this.textValue);
            // 添加一个li标签，只需要去改变list变量，不要去操作dom
            this.list.push(this.textValue);
            this.textValue = "";
          },
          removeItem(item) {
            // console.log(item);
            this.list = this.list.filter((value) => value !== item);
          },
        },
      });
    </script>
  </body>
</html>
